package com.naishuo.bigevent.service.impl;

import com.naishuo.bigevent.mapper.UserMapper;
import com.naishuo.bigevent.pojo.User;
import com.naishuo.bigevent.service.UserService;
import com.naishuo.bigevent.utils.Md5Util;
import com.naishuo.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User finfdByUsername(String username) {

       User user =  userMapper.findByUsername(username);
       return user;

    }

    @Override
    public void register(String username, String password) {

        //加密

        String md5Password = Md5Util.getMD5String(password);
        userMapper.register(username,md5Password);

    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String avatarUrl) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        userMapper.updateAvatar(avatarUrl,id);
    }

    @Override
    public void updatePassword(String newPassword,Integer id) {

        String md5Password = Md5Util.getMD5String(newPassword);
        userMapper.updatePassword(md5Password,id);
    }

    public static interface ArticleService {
    }
}
